<?php
namespace Pw\MainBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class HeroEditType extends AbstractType
{
	
	public function buildForm(FormBuilderInterface $builder, array $options) {
		$builder->add('name', 'text');
		$builder->add('lore', 'textarea', array('required' => false));
		$builder->add('hp', 'integer');
		$builder->add('mp', 'integer');
		$builder->add('speed', 'integer');
		$builder->add('strength', 'integer');
		$builder->add('intelligence', 'integer');
		$builder->add('agility', 'integer');
		$builder->add('artifice', 'integer');
		$builder->add('tenacity', 'integer');
		$builder->add('will', 'integer');
		$builder->add('side', 'choice', array('choices' => array('a' => 'Адорнийцы', 'd' => 'Докты')));
		$roles = $options['em']->getRepository('PwMainBundle:Role')->findAll();
		$choices = array();
		foreach ($roles as $role) {
			$choices[$role->getId()] = $role->getName();
		}
		$builder->add('roleId', 'choice', array('choices' => $choices));
		$heroes = $options['em']->getRepository('PwMainBundle:Hero')->findVisible();
		$choices = array('1' => 'Нет');
		foreach ($heroes as $hero) {
			$choices[$hero->getId()] = $hero->getName();
		}
		$builder->add('mirrorId', 'choice', array('choices' => $choices));
		$builder->add('icon', 'file', array('required' => false));
		$builder->add('art', 'file', array('required' => false));
	}
    public function getName() {
        return 'heroEdit';
    }
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Pw\MainBundle\Entity\Hero',
            'intention'       => 'heroEdit_item'
        ));
		$resolver->setRequired(array('em'));
    }
}
